package com.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.app.CasaCentral;
import com.bean.Cotizacion;

/**
 * Servlet implementation class ProcesarXMLCotizacion
 */
public class ProcesarCotizacion extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	       
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Cotizacion solicitudCotizacion = (Cotizacion) request.getSession().getAttribute("solicitudCotizacion");
		this.doProcesarCotizacion(request, response, solicitudCotizacion);
	}

	public void doProcesarCotizacion(HttpServletRequest request, HttpServletResponse response, Cotizacion solicitudCotizacion) throws ServletException, IOException {
		Cotizacion cotizacion = CasaCentral.getInstancia().cotizar(solicitudCotizacion);
		request.setAttribute("cotizacion", cotizacion);
	    RequestDispatcher dispatcher = request.getRequestDispatcher("/cotizacionConfirmacion.jsp");
		dispatcher.forward(request, response);
	}
}
